package com.xing.service.impl;

import com.xing.dao.ArticleTypeMapper;
import com.xing.entity.pojo.ArticleType;
import com.xing.entity.vo.ArticlePage;
import com.xing.entity.vo.ArticleTypePage;
import com.xing.service.ArticleTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.SessionTrackingMode;
import java.util.List;

@Service
public class ArticleTypeServiceImpl implements ArticleTypeService {
    @Autowired
    private ArticleTypeMapper articleTypeMapper;
    @Override
    public int deleteByPrimaryKey(String typeId) {
        return articleTypeMapper.deleteByPrimaryKey(typeId);
    }

    @Override
    public int insert(ArticleType record) {
        return articleTypeMapper.insert(record);
    }

    @Override
    public int insertSelective(ArticleType record) {
        return articleTypeMapper.insertSelective(record);
    }

    @Override
    public ArticleType selectByPrimaryKey(String typeId) {
        return articleTypeMapper.selectByPrimaryKey(typeId);
    }

    @Override
    public int updateByPrimaryKeySelective(ArticleType record) {
        return articleTypeMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(ArticleType record) {
        return articleTypeMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<ArticleType> findAll() {
        return articleTypeMapper.findAll();
    }

    @Override
    public ArticleTypePage findByPage(Integer currentPage, Integer rows, String typeName, Byte typeState) {
        ArticleTypePage ArticlePage=new ArticleTypePage();
        //每页几条
        ArticlePage.setRows(rows);
        //总条数
        int count = articleTypeMapper.findArticleTypeTotalCount(typeName,typeState);
        ArticlePage.setTotalCount(count);

        int start=(currentPage-1)*rows;
        //每页的记录
        ArticlePage.setList(articleTypeMapper.findCountAll(start,rows,typeName,typeState));
        //总页数
        ArticlePage.setTotalPage((count%rows==0)?(count/rows):(count/rows+1));
        //当前页
        ArticlePage.setCurrentPage(currentPage);
        return ArticlePage;
    }


    @Override
    public Boolean deleteckArticle(String[] ids) {
        boolean flag=false;
        for (int i = 0; i <ids.length ; i++) {
            int i1 = articleTypeMapper.deleteByPrimaryKey(ids[i]);
            if(i1>0){
                flag=true;
            }else {
                flag=false;
            }
        }
        return flag;
    }


}
